package com.junjie.checkin.security.service;

import com.junjie.checkin.entity.TUser;
import com.junjie.checkin.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author 洪浚杰
 * @description
 * @date 2025/6/9 12:55
 */
@Service
public class AuthDetailsService implements UserDetailsService{
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        TUser user = userMapper.getUserByUsername(username);
        if (Objects.isNull(user)){
            throw  new UsernameNotFoundException("");
        }
        return new AuthDetails(user);
    }
}
